﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace RMS.Utils.Dicom.Commen
{
    class TransferSyntax
    {
        private static bool isImplicitVR = true;
        public static bool IsImplicitVR
        {
            get
            {
                return isImplicitVR;
            }
        }

        private static bool isLittleEndian = true;
        public static bool IsLittleEndian
        {
            get
            {
                return isLittleEndian;
            }
        }

        public static bool IsMachineLittleEndian
        {
            get { return BitConverter.IsLittleEndian; }
        }

        public static void CheckUID(string UID)
        {
            if (UID != null)
            {
                if (Regex.IsMatch(UID, "^1\\.2\\.840\\.10008\\.1\\.2"))
                {
                    switch (UID)
                    {
                        case "1.2.840.10008.1.2":
                            isImplicitVR = true;
                            isLittleEndian = true;
                            break;
                        case "1.2.840.10008.1.2.1":
                            isImplicitVR = false;
                            isLittleEndian = true;
                            break;
                        case "1.2.840.10008.1.2.2":
                            isImplicitVR = false;
                            isLittleEndian = false;
                            break;
                        case "1.2.840.10008.1.2.99":
                            throw new Exception("The deflated " +
                                "transfer syntax is not supported");
                        default:
                            // defaults for transfer syntax for JPEG
                            // (1.2.840.10008.1.2.4.*) and RLE
                            // (1.2.840.10008.1.2.5) encoding according
                            // to the DICOM standard
                            isImplicitVR = false;
                            isLittleEndian = true;
                            break;
                    }
                }
                else
                    throw new Exception("UID is not a valid transfer.");
            }
            else
                throw new Exception("UID is null.");
        }

    }
}
